# Inits
require(OpenMx)
mxOption(NULL,"Default optimizer","SLSQP")
require(rio)
require(umx)
require(semTools)
require(MASS)




# Load data
setwd("D:/replication files")
data<-import("dataset_r.dta")
data<-data[data$TwinNr %in% 1,]
mzData <- data[data$zyg %in% 1,]
dzData <- data[data$zyg %in% 2,]


# Wealth and free market
wealth_freemarket = umxCI(umxACEv(selDVs = c('wealth','free_market'),mzData=mzData,dzData=dzData,sep='',addCI=T),run="yes")

# Wealth and leftright
wealth_leftright = umxCI(umxACEv(selDVs = c('wealth','leftright'),mzData=mzData,dzData=dzData,sep='',addCI=T),run="yes")

wealth_party = umxCI(umxACEv(selDVs = c('wealth','party'),mzData=mzData,dzData=dzData,sep='',addCI=T),run="yes")

# Finwealth and redistribution (requires two runs to get out of non-convex solution)
finwealth_redistribution = umxCI(umxACEv(selDVs = c('finwealth','redistribution'),mzData=mzData,dzData=dzData,sep='',addCI=T),run="yes")
fr2=umxCI(mxRun(model=finwealth_redistribution),run="yes")

# Real wealth and property taxes
realwealth_propertytax = umxCI(umxACEv(selDVs = c('realwealth','property_tax'),mzData=mzData,dzData=dzData,sep='',addCI=T),run="yes")



